{% extends "base.html" %}
{% load i18n %}
{% block title %} {% trans 'Relationship List' %}{% endblock %}
{% block meta %}
<script>
function save_relation(to_user_id, from_user_id, status_id){
	$(document).ready(function(){
		if(to_user_id == from_user_id){
			alert("Can't Relationship to yourself !");
			return false;
		}else{
		$('#user_non_rela_'+to_user_id).hide();
		  $.ajax({ // create an AJAX call...
		          data: { to_user: to_user_id, from_user: from_user_id, status: status_id },	//data send to ajax url
		          type: $(this).attr('GET'), // GET or POST
		          url: '/circle/relation_ajax/', // the file to call
		          //dataType : 'json',
		          success: function(response) { // on success..	*response = data send from view
		              $('#relation_list').html(response); // update the DIV Relationship List
		          }
	      });
		}
	});
}
</script>
{% endblock %}

{% block content %}
<legend> Relationship {{ relation_status }} From : {{ request.user.get_full_name }} To:</legend>
<div id="relation_list">
  {% for relation in relation %}
    <li>{{ relation.to_user.get_full_name }}
    	- <a href="{% url relationship_delete relation.pk relation.status %}"> Delete </a>
	</li>
  {% endfor %}
</div>
  	<a href="{% url relationship_add relation_status.id %}">{% trans 'Add' %}</a>
  	
  {% for user_non_relation in user_non_relations %}
  <div id="user_non_rela_{{ user_non_relation.id }}">
  	<li>{{ user_non_relation.get_full_name }}
  		- <a style="cursor:pointer;"><span onclick="save_relation({{ user_non_relation.id }}, {{ request.user.id }}, {{ relation_status.id }})">Add</span></a>
	</li>
  </div>
  {% endfor %}
{% endblock %}
